package com.zhny.aiot.lrh.data.plugin.model.util;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
    public static String getMd5(String text){
        byte[] md5Bytes = null;

        try {
            md5Bytes =MessageDigest.getInstance ("md5").digest (text.getBytes ("utf-8"));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException ("no found md5 secret !",e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException ("no support md5 secret !",e);
        }

        String md5Code = new BigInteger (1,md5Bytes).toString (16);
        for (int i = 0;i < 32 -md5Code.length ();i++){
            md5Code = "0"+md5Code;
        }
        return md5Code;
    }
}
